<?php 
/**
 * Parameters
 * @param OrganizationalUnit $organizational_unit Current Organizational Unit
 * @param Doctrine_Collection $members Collection of members assigned to the current organizational unit
 * @param array $form_errors [optional]
 */
  use_stylesheets_for_form($batch_payment_form);
  use_javascripts_for_form($batch_payment_form);
  if(!isset($form_errors)) $form_errors = array();
?>
<?php slot('heading', $organizational_unit->getName());?>
<?php slot('current_nav_tab', 'member');?>
<?php slot('breadcrumb1', link_to('Mitglieder', 'organizational_unit_portal', $organizational_unit))?>
<?php slot('breadcrumb2', sprintf('Massen-Bezahlen %s', $year))?>

		<div class="x8">
			<?php include_partial('global/form_error_list', array('form_errors' => $form_errors))?>
			<form action="<?php echo url_for('organizational_unit_mass_payment_save', $organizational_unit)?>" method="post" id="members_mass_payment_form">	
            <?php echo $batch_payment_form->renderHiddenFields(); ?>
            <?php echo $batch_payment_form->renderGlobalErrors(); ?>
			<input type="hidden" value="<?php echo $year?>" name="year" /> 
			<table class="data display datatable" id="example">
				<thead>
					<tr>
						<th>Name</th>
						<th>Vorname(n)</th>
						<th>Zahlungsdatum</th>
						<th>Referenz</th>
						<th>Beitrag</th>
					</tr>
				</thead>
				<tbody>
				<?php if(count($members) > 0):?>
				<?php foreach($members as $i => $member):?>
					<?php $form = $batch_payment_form->getEmbeddedForm($member->getId());?>
					<tr>
						<td><?php echo $member->getLastName()?></td>
						<td><?php echo $member->getFirstName()?></td>
						<td><?php echo $form['date_of_payment']->render(array('style' => 'width: 80px;'));?></td>
						<td><?php echo $form['reference']->render(array('style' => 'width: 120px;'))?></td>
						<td><?php echo $form['amount']->render(array('style' => 'width: 80px;'));?></td>
					</tr>
				<?php endforeach;?>
				<?php else:?>
					<tr>
						<td colspan="4"><i>Keine Mitglieder gefunden.</i></td>
					</tr>
				<?php endif;?>
				</tbody>
			</table>
			
            </form>
		</div>
		
		<div class="x4">
			<h2 class="box">Werkzeugbox<img alt="Werkzeugbox" src="<?php echo image_path('icons/content_werkzeugbox.png')?>" /></h2>
			<table class="box_table subnavigation">
				<tbody>
					<tr>
						<td><a href="#" onClick="document.forms['members_mass_payment_form'].submit();return false;"><img alt="Massen-Bezahlen speichern" src="<?php echo image_path('icons/content_subnavigation_massenbezahlen.png')?>" />Massen-Bezahlen speichern</a></td>
					</tr>
					<tr>
						<td><a href="#"><img alt="Massen-Bezahlen speichern" src="<?php echo image_path('icons/content_subnavigation_massenbezahlen.png')?>" /> Geschäftsjahr: 
						<?php echo $year_change_form['year']->render(array('style' => 'width: 70px;'));?></a></td>
					</tr>
					<tr>
						<td><a href="<?php echo url_for('organizational_unit_portal', $organizational_unit)?>"><img alt="Abbrechen und zur &Uuml;bersicht" src="<?php echo image_path('icons/content_subnavigation_zurueck.png');?>" />Abbrechen</a></td>
					</tr>
				</tbody>
			</table>
		</div>
		<!-- Selectbox onChange listener -->
		<script type="text/javascript">
            $(function(){
              // bind change event to select
              $('#<?php echo $year_change_form['year']->renderId();?>').change(function () {
                  var year = $(this).val(); // get selected value
                  if (year) { // require a URL
                      window.location = '<?php echo url_for('organizational_unit_mass_payment_with_year', array('sf_subject' => $organizational_unit, 'year' => ''));?>' + year; // redirect
                  }
                  return false;
              });
            });
        </script>